
package me.fanchaoo.web.util.phonesms;

import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import me.fanchaoo.dbo.EmailDBO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;


@SuppressWarnings("unchecked")
@Component
public class PhoneMsmUtils {

    /**
     * 邮箱号
     */
    @Autowired
    private SmsConfig smsConfig;


    public  void  send(Map<String, Object> param,String phone) throws ClientException {
        DefaultProfile profile = DefaultProfile.getProfile("default",smsConfig.getAccessKeyId(),
                smsConfig.getAccessKeySecret());
        IAcsClient client = new DefaultAcsClient(profile);

        //这里不能修改
        CommonRequest request = new CommonRequest();
        //request.setProtocol(ProtocolType.HTTPS);
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");

        request.putQueryParameter("PhoneNumbers", phone);                    //手机号
        request.putQueryParameter("SignName", "CGQ的生活记录");    //申请阿里云 签名名称（ smsConfig.getSignName()）
        request.putQueryParameter("TemplateCode", smsConfig.getTemplateCode()); //申请阿里云 模板code（用的也是阿里云测试的）
        request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));
        CommonResponse response = client.getCommonResponse(request);


    }


}
